package com.red.star.macalline.data.mappers;

import com.red.star.macalline.data.core.base.MyMapper;
import com.red.star.macalline.data.entity.Fans;
import com.red.star.macalline.data.entity.FansCard;
import com.red.star.macalline.data.entity.Group;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author nofish.yan@gmail.com
 * @date 2018/2/7.
 */
public interface FansMapper extends MyMapper<Fans> {

    Fans getFansByVipOpenId(String vipOpenId);

    @Select(value = "select * from t_fans t where t.open_id = #{openId}")
    public Fans findFansByOpenId(String openId);

    /**
     * 获取c用户的专属导购师
     *
     * @param cFans
     * @return
     */
    public List<Integer> findMyEmpIdList(Fans cFans);

    /**
     * 根据导购员id查询粉丝
     *
     * @param bFansIds
     * @return
     */
    public List<Fans> findMyEmpFansList(List<Integer> bFansIds);

    /**
     * 查询扫描购买的联盟组
     *
     * @param cFans
     * @return
     */
    public List<Integer> findMyGroupIdList(Fans cFans);

    /**
     * 查询联盟组
     *
     * @param ids
     * @return
     */
    public List<Group> findMyGroupList(List<Integer> ids);

    public List<Group> findAllGroupList(List<Integer> ids);

    @Select(value = "select * from t_fans t where t.vip_open_id = #{vipOpenId}")
    public Fans findFansByVipOpenId(String vipOpenId);

    public void updateVipOpenId(Integer id);

    public void updateFansType(Fans fans);

    public List<Fans> findFansByFansCards(List<FansCard> fansCardList);

    @Select(value = "select * from t_fans where union_id = #{unionId}")
    Fans getFansByUnionId(String unionId);

    /**
     * 查询买过某个导购员蓄客卡的所有用户
     *
     * @param employeeId 导购员ID
     * @return 粉丝集合
     */
    List<Fans> listByStoredCardAndEmployee(Integer employeeId);

    @Select("SELECT tf.id, tf.avatar_url FROM t_fans as tf JOIN t_employee AS te ON tf.id = te.fans_id WHERE te.id = #{employeeId}")
    Fans findFansByEmployeeId(@Param("employeeId") Integer employeeId);

    @Select(value = "select * from t_fans t where t.union_id = #{unionId} order by t.id limit 1")
    Fans findFansByUnionId(@Param("unionId") String unionId);

    @Select(value = "select * from t_fans tf inner join t_vip tv on tf.vip_open_id = tv.vip_open_id where tv.mobile = #{mobile} limit 1")
    Fans findFansByMobile(@Param("mobile") String mobile);
}
